﻿using Microsoft.EntityFrameworkCore;

namespace _14EFCore学习;

class Program
{
    static async Task Main(string[] args)
    {
        /*
        using MyDbContext dbContext = new MyDbContext();
        Book b = new Book() { Author = "Test",Price = 30,PubTime = DateTime.Now,Title = "TestTitle"};
        dbContext.Books.Add(b);
        await dbContext.SaveChangesAsync();
        Console.WriteLine("数据已保存至数据库");
        */
        
        using MyDbContext dbContext = new MyDbContext();
        //var result = dbContext.Books.Single(b => b.Title == "test2");
        // for (int i = 0; i < 100; i++)
        // {
        //     Book book = new Book() { Title = $"Title{i}", Author = $"Author{i}", Price = i, PubTime = DateTime.Now };
        //     dbContext.Books.Add(book);
        // }
        await dbContext.Books.Where(b => b.Price > 5)
            .ExecuteUpdateAsync(setter => setter.SetProperty(b=>b.Title,b=>b.Title+"test"));
        //await dbContext.SaveChangesAsync();
        Console.WriteLine(Guid.NewGuid());
    }
}